package cn.jiajunsong.feignconsumer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class HelloConsumer {
    @Value("${helloWorld}")
    private String hello;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private HelloService helloService;

    @GetMapping("/consumer1")
    public String consumer1(){
        return restTemplate.getForEntity("http://hello-service/hello",String.class).getBody();
    }
    @GetMapping("/consumer2")
    public String consumer2(){
        return restTemplate.getForObject("http://hello-service/info",String.class);
    }
    @GetMapping("/consumer3")
    public String consumer3(){
        return helloService.hello();
    }
    @GetMapping("/consumer4")
    public String consumer4(){
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(helloService.hello()).append("\n");
        stringBuilder.append(helloService.hello("DIDI")).append("\n");
        stringBuilder.append(helloService.hello("DIDI",30)).append("\n");
        stringBuilder.append(helloService.hello(new User("Didi",20))).append("\n");
        return stringBuilder.toString();
    }
    @GetMapping("/consumer5")
    public String consumer5(){
        return hello;
    }
}
